/*
 * Author: xiguan
 * Mail: xiguan.teng@qq.com
 * -----
 * Last Modified: 2022-05-31 17:04:30
 * Modified By: xiguan
 * -----
 * Copyright (c) 2022 XiGuan Inc.
 * 
 * No Bug No error No warning.
 */


#include <bits/stdc++.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>
#include <time.h>


using namespace std;

void message_err(const char *msg){
    perror(msg);
    exit(1);
}


int main(int argc, char *argv[]){

    struct stat buf;
    
    if(argc < 2){
        printf("Usage: %s <file>\n", argv[0]);
        exit(1);
    }

    // 获取文件属性
    if(stat(argv[1], &buf) == -1){
        message_err("stat: ");
    }

    // 打印文件属性
    printf("device is : %ld\n", buf.st_dev);
    printf("inode is : %ld\n", buf.st_ino);
    printf("mode is : %o\n", buf.st_mode);
    printf("number of hard links is : %ld\n", buf.st_nlink);
    printf("user ID of owner is : %d\n", buf.st_uid);
    printf("group ID of owner is : %d\n", buf.st_gid);
    printf("device type (if inode device) is : %ld\n", buf.st_rdev);
    
    printf("total size. in bytes is : %ld\n", buf.st_size);
    printf("blocksize for filesystem I/O is : %ld\n", buf.st_blksize);
    printf("number of blocks allocated is : %ld\n", buf.st_blocks);

    printf("time of last access is : %s\n", ctime(&buf.st_atime));
    printf("time of last modification is : %s\n", ctime(&buf.st_mtime));
    printf("time of last change is : %s\n", ctime(&buf.st_ctime));
    

    return 0;
}
